package com.chb.javabasic.AOP;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LoggingAspect {

    @Pointcut("execution(* com.chb.javabasic.AOP.UserService.*(..))")
    public void serviceMethods(){

    }

    // 前置通知
    @Before("serviceMethods()")
    public void logBefore() {
        System.out.println("前置通知：方法开始执行...");
    }

    @After("serviceMethods()")
    public void logAfter() {System.out.println("后置通知: 方法执行结束");}

    @Around("serviceMethods()")
    public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("环绕通知： 方法开始执行");
        Object result = joinPoint.proceed();
        System.out.println("环绕通知： 方法执行完成");
        return result;
    }


}
